package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.CheckItemDao;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckItemServiceImpl implements CheckItemService {
    @Autowired
    private CheckItemDao checkItemDao;
    @Override
    public void add(CheckItem checkItem) {
        checkItemDao.add(checkItem);
    }

    @Override
    public void delete(Long id) {
        checkItemDao.delete(id);
    }

    @Override
    public CheckItem findById(Long id) {
        return checkItemDao.findById(id);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        //下一条sql进行分页，自动加入limit关键字分页
        Page<CheckItem> page = checkItemDao.pageQuery(queryPageBean);
        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void edit(CheckItem checkItem) {
        checkItemDao.edit(checkItem);
    }

    @Override
    public List<CheckItem> findAll() {
        return checkItemDao.findAll();
    }

    @Override
    public List<String> findCheckItemIdsByCheckGroupId(Long checkgroupId) {
        return checkItemDao.findCheckItemIdsByCheckGroupId(checkgroupId);
    }
}
